import React, {FC, useState} from "react";
import {produce} from "immer";

const List2 : FC = ()=>{

    const [userInfo,setUserInfo] = useState({name:"xiao",age: 12});

    function changeClick() {
            setUserInfo(
                produce(p=>{
                    p.age=21;
                })
            )
    }

    return (<div>
          <h2>数据不可变</h2>
          <div> {JSON.stringify(userInfo)}</div>
         <button onClick={changeClick}>change age</button>
    </div>);
}

export default List2;